#include <iostream>
#include <pthread.h>
#include <ctime>
#include <string>
using namespace std;


typedef void*(*callback_t)(void*);

//不能再前面初始化，人家还不认识Thread类呢
//int Thread::counter = 1;

class Thread
{
public:
    Thread(callback_t cb, void* argv = nullptr)
        :_is_running(false)
        ,_cb(cb)
        ,_argv(argv)
    {}
        
    
    void run()
    {
        pthread_create(&_pid, nullptr, _cb, _argv);
        _start_time = time(nullptr);
        _is_running = true;
        _name = "Thread - " + to_string(counter++); 
    }

    void join()
    {
        pthread_join(_pid, nullptr);
        _is_running = false;
    }

    bool isrunning() {  return _is_running;}
  
    uint64_t StartTime() {  return _start_time;}

    pthread_t GetPid() { return _pid;}
 
    string GetName() { return _name;}
  
    ~Thread() { }
   
private:
    pthread_t _pid;
    string _name;
    uint64_t _start_time;
    bool _is_running;

    callback_t _cb;
    void* _argv;

    static int counter;
};


int Thread::counter = 1;

